<?php

namespace App\Providers;

use App\Extensions\MyValidator;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{

//    static $notifVars;

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        ini_set('memory_limit', "1024M");


        //prevent error
        //SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
        Schema::defaultStringLength(191);

        //https://stackoverflow.com/questions/36922644/add-view-name-to-css-class-on-body/43692763#43692763
        //Then you can access $view_name variable in your view.
        //e.g <body class="{{$view_name}}">
//        View::composer(
//            '*',
//            function ($view) {
//                if ($view->getName() == "video.show") {
//                    $view_name = str_replace('.', '___', $view->getName());
//                } else {
//                    $view_name = str_replace('.', ' ', $view->getName());
//                }
//                //replace card class because inteferes with bootstrap
//                $view_name = str_replace('card', 'cards', $view_name);
//                View::share('view_name', $view_name);
//            }
//        );


        Validator::resolver(
            function ($translator, $data, $rules, $messages) {
                return new MyValidator($translator, $data, $rules, $messages);
            }
        );
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
//        $this->app->bind(
//            TranslateClient::class,
//            function () {
//                return new TranslateClient(
//                    [
//                        'key' => config('app.google_key'),
//                    ]
//                );
//            }
//        );

        if ($this->app->environment() !== 'production') {
            $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
        }
//

//        // 注册 JPush 客户端单例
//        $this->app->singleton(
//            JPushClient::class,
//            function ($app) {
//                $config = require_once base_path("config") . DIRECTORY_SEPARATOR . "jpush.php";
//                Log::info("jpush config", [$config]);
//                $key = $config['key'];
//                $secret = $config['secret'];
//                $log = $config['log'];
//
////                throw new InvalidArgumentException("key=$key ; secret=$secret ; log=$log");
//
//                return new JPushClient($key, $secret, $log);
//            }
//        );

    }


}
